package nettest;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.MalformedURLException;
import java.net.URL;

public class J_Url {
    public static void main(String[] args){
        try {
            URL url = new URL("http://www.tsinghua.edu.cn/publish/thu2018/index.html");
            System.out.println("protocol-->"+url.getProtocol());
            System.out.println("host    -->"+url.getHost());
            System.out.println("file    -->"+url.getFile());
            System.out.println("port    -->"+url.getPort());
            System.out.println("reference-->"+url.getRef());
            System.out.println("-------------------------------------------------------------------");
            BufferedReader reader = new BufferedReader(new InputStreamReader(url.openStream()));
            String s;
            while ((s=reader.readLine())!=null){
                System.out.println(s);
            }
            reader.close();
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
